# -*- coding:utf-8 -*-

from server.util import errors, stringUtil


def ifSocket(key, data):  # socket from base
    # 合法性检测
    arr = data.split(",")
    newstr = ''
    for i in range(len(arr) - 1):
        if i == len(arr) - 2:
            newstr = newstr + arr[i]
        else:
            newstr = newstr + arr[i] + ","

    sh = stringUtil.get_hmac(key, newstr)
    if sh == arr[-1]:  # hmac验证通过
        print "request data:", data
        return True, arr
    else:
        return False, None
